package com.wangsd.web.shop.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wangsd.common.basicbean.MyController;
import com.wangsd.common.basicbean.Result;
import com.wangsd.web.shop.entity.Merchant;
import com.wangsd.web.shop.entity.Store;
import com.wangsd.web.shop.service.MerchantService;
import com.wangsd.web.shop.service.StoreService;
import com.wangsd.web.sys.entity.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "支付商户管理")
@RestController
@RequestMapping("/shop/store")
@Slf4j
public class StoreController extends MyController {
    @Resource
    private StoreService service;

    @ApiOperation(value = "分页查询列表")
    @PostMapping("/selectPage")
    public Object selectPage(@ApiParam(value = "当前第几页", required = true) @RequestParam("pageNum") Integer pageNum,
                             @ApiParam(value = "每页结果集大小", required = true) @RequestParam("pageSize") Integer pageSize,
                             Store queryObj) {
        SysUser loginUser = getUserInfo();
        Page page = PageHelper.startPage(pageNum, pageSize);
        List<Store> list = service.selectPage(queryObj, loginUser.getParentCode());
        return Result.success(getPageInfo(page, list));
    }

    @ApiOperation(value = "新增或者修改")
    @PostMapping("/saveOrUpdate")
    public Object saveOrUpdate(@RequestBody Store entity) {
//        entity.setUsableAmount(entity.getUsableAmount() * 100);
        service.saveOrUpdate(entity);
        return Result.success();
    }

    @ApiOperation(value = "删除支付商户")
    @GetMapping("/{id}/delete")
    public Result delete(@ApiParam(value = "客户(商圈)id", required = true) @PathVariable Long id) {
        service.deleteById(id);
        return Result.success();
    }


    @ApiOperation(value = "查询树形结构")
    @PostMapping("/selectStoreTree")
    public Object selectStoreTree(boolean isDisable) {
        SysUser loginUser = getUserInfo();
        List list = service.selectStoreTree(isDisable, loginUser.getParentCode());
        return Result.success(list);
    }

}
